package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AlarmAnalyse;

import com.ruoyi.system.service.IAlarmAnalyseService;
import com.ruoyi.system.service.IEquipmentManageService;
import com.ruoyi.system.service.impl.EquipmentManageServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

import java.util.Date;
import java.util.List;

/**
 * 报警处理Controller
 *
 * @author ruoyi
 * @date 2023-07-07
 */
@Api("设备报警分析")
@RestController
@RequestMapping("/system/analyse")
public class AlarmAnalyseController extends BaseController {

    @Autowired
    private IAlarmAnalyseService alarmAnalyseService;

    /**
     * 查询报警信息列表
     */
    @ApiOperation("查询设备报警分析列表")
    @PreAuthorize("@ss.hasPermi('system:analyse:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmAnalyse dto) {
        startPage();
        List<AlarmAnalyse> list = alarmAnalyseService.selectAlarmAnalyseList(dto);
        return getDataTable(list);
    }

    /**
     * 获取报警信息详细信息
     */
    @ApiOperation("获取报警信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:analyse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(alarmAnalyseService.selectAlarmAnalyseById(id));
    }


    /**
     * 导出设备报警分析列表
     */
    @ApiOperation("导出设备报警分析列表")
    @PreAuthorize("@ss.hasPermi('system:analyse:export')")
    @Log(title = "设备报警分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmAnalyse alarmAnalyse) {
        List<AlarmAnalyse> list = alarmAnalyseService.selectAlarmAnalyseList(alarmAnalyse);
        ExcelUtil<AlarmAnalyse> util = new ExcelUtil<AlarmAnalyse>(AlarmAnalyse.class);
        util.exportExcel(response, list, "设备报警分析数据");
    }

    /**
     * 新增数据报警分析
     */
    @PreAuthorize("@ss.hasPermi('system:analyse:add')")
    @Log(title = "设备报警分析", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmAnalyse alarmAnalyse) {
        return toAjax(alarmAnalyseService.insertAlarmAnalyse(alarmAnalyse));
    }

    /**
     * 修改数据报警分析
     */
    @PreAuthorize("@ss.hasPermi('system:alarmAnalyse:edit')")
    @Log(title = "设备报警分析", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmAnalyse alarmAnalyse) {
        return toAjax(alarmAnalyseService.updateAlarmAnalyse(alarmAnalyse));
    }

    /**
     * 删除数据报警分析
     */
    @PreAuthorize("@ss.hasPermi('system:alarmAnalyse:remove')")
    @Log(title = "设备报警分析", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(alarmAnalyseService.deleteAlarmAnalyseByIds(ids));
    }
    /**
     * 查询报警信息经纬度
     */
    @ApiOperation("地图：获取经纬度")
    @PreAuthorize("@ss.hasPermi('system:analyse:listmap')")
    @GetMapping("/listmap/{snNum}")
    public TableDataInfo list(@PathVariable("snNum")String snNum) {
        startPage();
        List<AlarmAnalyse> listmap = alarmAnalyseService.selectAlarmAnalyseListMap(snNum);
        return getDataTable(listmap);
    }
    /**
     * 查询报警值
     */
    @ApiOperation("查询设备报警值")
    @GetMapping("/listNum")
    public TableDataInfo listnum(AlarmAnalyse alarmAnalyse){
        List<AlarmAnalyse> listNUm = alarmAnalyseService.selectAlarmAnalyseListNUm(alarmAnalyse);
        return getDataTable(listNUm);
    }

}
